<?php

namespace Kunfeng\Dify\Event;

/**
 * 事件工厂类
 */
class EventFactory
{
    public static function create(string $eventType, array $data): BaseEvent
    {
        switch ($eventType) {
            case 'message':
                return new MessageEvent($eventType, $data);
            case 'message_end':
                return new MessageEndEvent($eventType, $data);
            case 'message_file':
                return new MessageFileEvent($eventType, $data);
            case 'tts_message':
                return new TtsMessageEvent($eventType, $data);
            case 'tts_message_end':
                return new TtsMessageEndEvent($eventType, $data);
            case 'message_replace':
                return new MessageReplaceEvent($eventType, $data);
            case 'agent_message':
                return new AgentMessageEvent($eventType, $data);
            case 'agent_thought':
                return new AgentThoughtEvent($eventType, $data);
            case 'agent_log':
                return new AgentLogEvent($eventType, $data);
            case 'workflow_started':
                return new WorkflowStartedEvent($eventType, $data);
            case 'workflow_finished':
                return new WorkflowFinishedEvent($eventType, $data);
            case 'node_started':
                return new NodeStartedEvent($eventType, $data);
            case 'node_finished':
                return new NodeFinishedEvent($eventType, $data);
            case 'iteration_started':
                return new IterationStartedEvent($eventType, $data);
            case 'iteration_next':
                return new IterationNextEvent($eventType, $data);
            case 'iteration_completed':
                return new IterationCompletedEvent($eventType, $data);
            case 'loop_started':
                return new LoopStartedEvent($eventType, $data);
            case 'loop_next':
                return new LoopNextEvent($eventType, $data);
            case 'loop_completed':
                return new LoopCompletedEvent($eventType, $data);
            case 'workflow_text_chunk':
                return new WorkflowTextChunkEvent($eventType, $data);
            case 'error':
                return new ErrorEvent($eventType, $data);
            case 'ping':
                return new PingEvent($data);
            default:
                throw new \InvalidArgumentException("Unknown event type: {$eventType}");
        }
    }
}
